// Learn TypeScript:
//  - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html

import config from "../config/config";
import func from "../config/func";
import AdManage from "../manage/AdManage";
import AudioManage from "../manage/AudioManage";

const { ccclass, property } = cc._decorator;

@ccclass
export default class CutTime extends cc.Component {

    @property(cc.Node)
    node_bg: cc.Node = null;

    // onLoad () {}

    init() {
        config.openPopup = false;
        func.creatVivoNativeAd();
    }

    click() {
        AudioManage.audioManage.playEffectMusic(config.soundPath.click);
        let id = "";
        if (config.gameType == "vivo") {
            id = config.vivoRewardedVideoAd;
            cc.audioEngine.setMusicVolume(0);
        } else if (config.gameType == "QQ") {
            id = config.qq_videoAd;
        }
        AdManage.instance.initRewardedVideoAd(id, (res: any) => {
            if (res == 1) {
                this.reward();
            }
        })
    }

    reward() {
        config.cutTime = 0.5;
    }

    close() {
        AudioManage.audioManage.playEffectMusic(config.soundPath.click);
        this.node.active = false;
    }

    // update (dt) {}
}
